package p3as.cliente;
import java.awt.Graphics;



public class Ball implements Drawable {
   
    private int x;
    private int y;
    private int dx;
    private int dy;
    private int width = 10;
    private int heigth = 10;
    
    
    public Ball(int x, int y, int dx, int dy){
        this.x = x;
        this.y = y;
        this.dx = dx;
        this.dy = dy;
    }

    public int getDx() {
        return dx;
    }

    public void setDx(int dx) {
        this.dx = dx;
    }

    public int getDy() {
        return dy;
    }

    public void setDy(int dy) {
        this.dy = dy;
    }

    @Override
    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    @Override
    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
    
    @Override
    public void addChild(Drawable drawable) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void removeChild(Drawable drawable) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Drawable getChild(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int collision(Drawable drawable) {
        if(drawable != this){
            Ball ball = (Ball) drawable;
            double distancia = Math.sqrt(Math.pow(((this.x + this.width/2) - (ball.getX() + this.width/2)),2) + Math.pow(((this.y + this.heigth/2) - (ball.getY() + this.width/2)), 2));
                if(distancia <= this.width){
                    ball.setDx(ball.getDx()*(-1));
                    ball.setDy(ball.getDy()*(-1));
                    return 0;
                }
        }
        return 0;
    }

    @Override
    public void render(Graphics graphics) {
        graphics.drawOval(x, y, width, heigth);
    }
    
    public void move(){
        this.setX(this.getX()+this.getDx());
        this.setY(this.getY()+this.getDy());
    }

    @Override
    public int getWidth() {
        return width;
    }

    @Override
    public int getHeigth() {
        return heigth;
    }

    @Override
    public void setScore(Score score) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
